<?php

class ProductsController extends Controller
{
    public $categories;
    public $pages;

    public function actionShow($id='',$layout='')
    {
        if($id){
			$criteria = new CDbCriteria();
			$criteria->select = 'id, name';
			$criteria->condition = 'status = :status';
			$criteria->params = array(':status'=> 1);
			$this->categories = Category::model()->findAll($criteria);


			$criteria = new CDbCriteria();
			$criteria->select = 'id, name, on_sale, image, code, packing, last_update, description';
			$criteria->condition = 'status = :status and id = :id';
			$criteria->params = array(':status'=> 1, ':id' => $id);
			$product = Product::model()->find($criteria);
		}
        else
			$product = null;
        if($product === null)
            throw new CHttpException(404,'The requested page does not exist.');

        //Set layout show-product view
        if($layout){
            $this->layout = 'ProductPopupLayout';
        }else{
            $this->layout = 'ProductLayout';
        }
        $this->render("Index", array("product" => $product));
        
    }

}